package com.wtgroup.demo.common.bean;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/4/16 15:46
 */
public class DoubleNode {
    public int val;
    public DoubleNode prev;
    public DoubleNode next;

    public DoubleNode() {}
    public DoubleNode(int val) {this.val = val;}

    public static DoubleNode toDoubleNode(int... arr) {
        DoubleNode dummyHead = new DoubleNode();
        DoubleNode prev = dummyHead;
        DoubleNode cur = null;
        for (int k : arr) {
            cur = new DoubleNode(k);
            prev.next = cur;
            cur.prev = prev;
            prev = cur;
        }

        dummyHead.next.prev = null;

        return dummyHead.next;
    }

    public static void print(DoubleNode head) {
        StringBuilder sb = new StringBuilder();
        while (head != null) {
            if (sb.length()>0) {
                sb.append(head.prev == null ? "->" : "<->");
            }
            sb.append(head.val);
            head = head.next;
        }
        System.out.println(sb.toString());
    }
}
